#include <cgic.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
extern char* cgiQueryString;

int cgiMain(){
    char gatewayIp[128];
    char location[256];
    //读取配置信息
    cgiFormString("gatewayIp",gatewayIp,128);
    cgiFormString("location",location,256);
    // 使用glib将数据保存到ini配置文件中区
    // 从配置文件中读取配置文件路径
    GKeyFile* file=g_key_file_new();
    g_key_file_load_from_file(file,"../config/config.ini",G_KEY_FILE_NONE,NULL);
    gchar* path=g_key_file_get_string(file,"config","deviceInfoPath",NULL);
    GKeyFile *keyFile=g_key_file_new();
    g_key_file_set_string(keyFile,"config","gatewayIp",gatewayIp);
    g_key_file_set_string(keyFile,"config","location",location);
    g_key_file_save_to_file(keyFile,path,NULL);
    g_key_file_free(keyFile);
    // 返回提示操作成功
    cgiHeaderContentType("text/html");
    // 响应一个html网页
	fprintf(cgiOut, "<HTML><HEAD><meta charset=\"UTF-8\">\n");
	fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1>cgic测试 请求数据:gatewayIp:%s,location:%s</H1>\n",gatewayIp,location);
    fprintf(cgiOut,"</BODY></HTML>");
    return 0;
}